﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace GameStateManagement
{
    class Sprite 
    {        
        public Vector2 Position = new Vector2(0,0);
        public Vector2 spriteSPEED = new Vector2(1,1);
        Texture2D mTexture;
        public string mName;

        public Rectangle Size;
        private float mScale = 1.0f;
        public float Scale
        {
            get { return mScale; }
            set
            {
                mScale = value;
                //Recalculate the Size of the Sprite with the new scale
                Size = new Rectangle((int)Position.X, (int)Position.Y, (int)(mTexture.Width * Scale), (int)(mTexture.Height * Scale));
            }
        }

        //constructor
        public Sprite() 
        {      
        }

        //This function is responsible for loading the texture to the class
        //call this function from the LoadContent function in your game
        public void LoadContent(ContentManager Manager, string Asset)
        {
            mName = Asset;
            mTexture = Manager.Load<Texture2D>(mName);
            
            Size = new Rectangle((int)Position.X, (int)Position.Y, (int)(mTexture.Width * Scale), (int)(mTexture.Height * Scale));
        }

        //The following is responsible for updating the sprite on the screen
        public void Update(GameTime theGameTime, Vector2 theSpeed, Vector2 theDirection)
        {
            Position += theDirection * theSpeed * (float)theGameTime.ElapsedGameTime.TotalSeconds;
        }
               
        //This function is in charge of drawing the sprite to the screen
        //call this from the Draw function in your game
        //Draw the sprite to the screen
        public void Draw(SpriteBatch theSpriteBatch)
        {
            theSpriteBatch.Draw(mTexture, Size,Color.White);//, 0.0f, new Vector2(Size.X,Size.Y), Scale, SpriteEffects.None, 0);
        }
    }
}


